/*********************************************************
 *	Description:	AppC file. Descripe the connection between 
 *				the modules.
 *	Project:		SurF
 *	Author:		Zheng Xiaolong
 *	Updated:		2012/10/23
 *********************************************************/
 
#include <Timer.h>
#include "SurF.h"
#include "printf.h"

configuration SurFAppC {
}
implementation {
  components MainC, TimeSyncC;
  components LedsC;
  components SurFC as App;
  components new TimerMilliC();
  components new TimerMilliC() as Timer0;
  components new TimerMilliC() as Delay;
  components new TimerMilliC() as StartTimer;
  components new TimerMilliC() as DATATimer;
  components new TimerMilliC() as REQTimer;
  components new TimerMilliC() as ADVTimer;
  components ActiveMessageC;
  components new AMSenderC(AM_SURFFLOODING);
  components new AMReceiverC(AM_SURFFLOODING);
  components new AMSenderC(AM_SURFADVMSG) as SendAdvMsg, 
  	new AMReceiverC(AM_SURFADVMSG) as ReceiveAdvMsg,
	new AMSenderC(AM_SURFREQMSG) as SendReqMsg, 
	new AMReceiverC(AM_SURFREQMSG) as ReceiveReqMsg,
	new AMSenderC(AM_SURFDATAMSG) as SendDataMsg, 
	new AMReceiverC(AM_SURFDATAMSG) as ReceiveDataMsg;
	App.SendAdvMsg -> SendAdvMsg;
	App.ReceiveAdvMsg -> ReceiveAdvMsg;
	App.SendReqMsg -> SendReqMsg;
	App.ReceiveReqMsg -> ReceiveReqMsg;
	App.SendDataMsg -> SendDataMsg;
	App.ReceiveDataMsg -> ReceiveDataMsg;


  components CC2420ActiveMessageC;
	App.CC2420Packet -> CC2420ActiveMessageC;

  components RandomC;
  components BcastC;
  components SerialActiveMessageC;
  components ExtDebugLogP as DebugSender;
  components new SerialAMSenderC(0xAC) as UARTSender;
  components new SerialAMSenderC(CL_TEST);
  components new QueueC(message_t*, 24);
  components new PoolC(message_t, 24);
  
  TimeSyncC.Boot -> MainC;
  MainC.SoftwareInit -> TimeSyncC;
  App.Random -> RandomC.Random;
  App.Boot -> MainC;
  App.Leds -> LedsC;
  App.StartTimer -> StartTimer;
  App.Timer0 -> Timer0;
  App.DATATimer -> DATATimer;
  App.REQTimer -> REQTimer;
  App.ADVTimer -> ADVTimer;
  App.Delay -> Delay;
  App.Packet -> AMSenderC;
  App.AMPacket -> AMSenderC;
  App.AMControl -> ActiveMessageC;
  App.AMSend -> AMSenderC;
  App.Receive -> AMReceiverC;

  App.Bcast -> BcastC;
  App.PacketTimeStamp -> ActiveMessageC;
  App.GlobalTime -> TimeSyncC;
  App.TimeSyncInfo -> TimeSyncC;


  App.UARTSend -> SerialAMSenderC.AMSend;
  App.SerialReceive -> SerialActiveMessageC.Receive[CL_TEST];

  App.Pool -> PoolC;
  App.Queue -> QueueC;


#ifdef ENABLE_EXTLOG

  App.SerialControl -> SerialActiveMessageC;

  components new PoolC(CollectionDebugMsg, 50) as DebugMessagePool;
  components new QueueC(CollectionDebugMsg*, 50) as DebugSendQueue;

  DebugSender.UARTSend -> UARTSender;
  DebugSender.Pool -> DebugMessagePool;
  DebugSender.Queue -> DebugSendQueue;
  
  //Collector.CollectionDebug -> DebugSender; // log in the ctp component
  App.CollectionDebug -> DebugSender; // log in our application
  
  //DebugSender.Timer -> TimerMilliC;
  
  components new LogStorageC(VOLUME_LOGTEST, TRUE); // circular
  DebugSender.LogRead -> LogStorageC;
  DebugSender.LogWrite -> LogStorageC;

  components LedsC as LedsC0;
  DebugSender.Leds -> LedsC0;

  App.LogControl -> DebugSender;
  components new TimerMilliC() as DelayTimerC;
  App.DelayTimer -> DelayTimerC;

#endif


}
